package org.texteasy;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MessagesInProgessList extends ListActivity {

	private static final String TAG = "MessagesInProgessList"; 
	
	String[] messages = new String[]{"This is sample text and represents a " +
		"message someone would send. Perhapse they would send a message about a party or " +
		"a reminder to buy something at the store. Whatever it is the contents of that message" +
		"would appear here.", "Another test, short message this time", "OK"};
	
	String[] statuses = new String[]{"Sent", "In Progress", "Waiting"};
	
	String[] sentMessagesCount = new String[]{"4 of 4", "11 of 200", "0 of 77"};
	
	private static final int CANCEL_ID = Menu.FIRST;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setListAdapter(new InProgressListAdapter(this));
		getListView().setOnCreateContextMenuListener(this);
	}
	
	
	@Override
    public void onCreateContextMenu(ContextMenu menu, View v,
    		ContextMenuInfo menuInfo) {
    	//super.onCreateContextMenu(menu, v, menuInfo);
    	
        menu.setHeaderTitle("First x characters of a message contents");
        
        //Add a menu item to delete the note
        menu.add(0, CANCEL_ID, 0, R.string.MESSAGES_IN_PROGRESS_CANCEL);
    }
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		Intent intent = new Intent(this, MessageEditor.class);
        /*intent.putExtra(MessageEditor.NAME, new String[]{"Blah 1", "blah 2", "blah 3"});
        intent.putExtra(MessageEditor.LABEL, new String[]{"Mobile","Home", "Mobile"});
        intent.putExtra(MessageEditor.NUMBER, new String[]{"214-555-5555", "972-555-5555", "469-555-5555"});
        intent.putExtra(MessageEditor.COUNT, 3);
        */
        startActivity(intent);
	}
	
	private final class InProgressListAdapter extends ArrayAdapter<String>{
		
		private Activity context;
		
		public InProgressListAdapter(Activity context) {
			
			super(context, R.layout.selection_list, messages);
			
			this.context = context;
		}
		
		
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			
			View row = convertView;
			
			if(row == null){
				LayoutInflater inflater = context.getLayoutInflater();
				row = inflater.inflate(R.layout.in_progress_row, null);
			}
			
			TextView status = (TextView)row.findViewById(R.id.message_status);
			status.setText(statuses[position]);
			
			TextView sentCount = (TextView)row.findViewById(R.id.message_sent_count);
			sentCount.setText(sentMessagesCount[position]);
			
			TextView messageContents = (TextView)row.findViewById(R.id.message_contents);
			messageContents.setText(messages[position]);
			
			return row;
		}
		
	}
}
